paoshangMgr = {}
QMPlugin = paoshangMgr
function paoshangMgr.init(maxCount)
    paoshangMgr.maxCount = maxCount or 99
    paoshangMgr.curCount = 0
    if boot.platform == 1 then
        paoshangMgr.paraConfig = {
            ["跑商头顶标记"] = {  685,908,792,1013,"4CF6FF-303030","-2|-20|35A2E2,-31|4|72C5FB,-7|25|519EED,21|-2|96F6FF,-23|10|538FEB,-11|16|3099EC,-12|-14|289CED",0,0.95},
            ["跑商任务菜单关闭"] = {76,243,958,662,"95CFFD","15|-59|1A2B73,-4|-40|1A2D74,4|5|1C2F76,2|-10|1B2D75,16|-10|1F3278,15|20|1D3077,6|128|5478B8,-5|141|5276B7,8|152|5578B8",0,0.9},
            ["跑商任务已领取"] = {61,262,973,671,"192A72-303030","11|-27|192A72,9|-61|192A72,-15|-60|192A72,-12|35|1A2B73,-9|25|192A72,11|52|192A72,0|40|192A72,-14|51|192A72,-17|62|192A72",0,0.9},
            ["跑商任务已完成"] = { 72,268,959,671,"D3E5DC-303030","11|-17|5ABE67,-14|-18|58BE66,-25|-2|59BD66,-16|13|5ABB66,10|14|5ABE67,7|-2|C4DBCF,5|-11|E6F2F0,2|9|E9F2F2,-10|9|E5F1ED",2,0.9},
            ["跑商任务已完成立即前往"] = { 93,1368,184,1655,"D1F0FF-303030","6|-115|4D56D6,10|97|4F58D9,-5|-82|D1F0FF,27|57|D1F0FF,26|7|D1F0FF,-7|11|D1F0FF,-3|-14|D1F0FF,-7|-20|D1F0FF,-5|-27|D1F0FF",2,0.9},
            ["跑商任务前往"] = {15,1039,1070,1913,"182971-303030","-2|36|182971,-15|38|182971,38|-322|192A72,16|-321|192A72,13|-315|192A72,35|-355|192A72,8|-522|4D93D8,-12|-516|498ED4,27|-373|192A72",0,0.9},
            ["跑商任务"] = {9,1046,1015,1913,"192A72-303030","23|-23|192A72,3|-46|192A72,3|-49|192A72,25|-41|192A72,-8|-194|8FB2D3,10|-186|5AA0DF,-25|-208|468BD4,-18|-175|FDFEFF,-53|-137|4D75F6",0,0.95},
            ["跑商任务领取按钮"] = { 533,1413,630,1862,"F4FCFE-303030","9|-73|F4FCFE,-11|-61|F4FCFE,-10|-26|F4FCFE,4|-17|F4FCFE,14|1|F4FCFE,-4|8|F4FCFE,-7|14|F4FCFE,15|32|DFE7EC,-11|39|F4FCFE",0,0.9},
            ["跑商任务马上出发按钮"] = {423,1425,526,1850,"F4FCFE-303030","4|-50|F4FCFE,-3|-52|F4FCFE,-19|-53|F4FCFE,-18|-27|F3FBFE,7|22|F4FCFE,-17|42|F4FCFE,-19|63|F4FCFE,-7|63|F4FCFE,3|63|F4FCFE",0,0.9},
            ["小地图三角按钮"] = {863,1676,1079,1919,"1DDCFF-303030","5|-14|1ED1F6,-13|-4|1DDCFF,2|8|21DEFF",0,0.9},
            ["世界地图按钮"] = {136,1457,222,1680,"C3E7FF-303030","18|-165|182A71,-6|-144|192A71,11|-143|192A71,12|-112|192A71,1|-111|192A71,15|-82|192A71,-2|-80|192A71,2|-18|C5E8FF,17|-11|CFF2FF",0,0.9},
            ["大唐国境"] = {514,781,724,1014,"374BA8-303030","45|-63|CDF1F8,42|-77|4F7291,21|-74|C1E4F1,21|-52|D3F4FF,17|-63|D3F7FB,-9|-64|D0F1FD,-17|-70|D0F1F8,-39|-54|C0E4EF,-67|-50|D2F9FF",0,0.9},
            ["地图放大镜"] = { 132,323,242,421,"AEDFFE-303030","10|-12|4154A0,-11|-6|40539E,10|8|40529F,-6|10|40529F,-18|20|40529F,6|28|AFE0FE,-23|-20|A9DDFD",0,0.9},
            ["跑商货品购买按钮"] = {349,1547,407,1694,"F4FCFE-303030","22|-14|F4FCFE,20|-51|F4FCFE,4|-56|F4FCFE,-3|-42|F4FCFE,-4|6|F4FCFE,-3|29|F4FCFE,5|37|F4FCFE,-1|38|F4FCFE,-4|45|F4FCFE",0,0.9},
            ["跑商任务过期"] = { 37,62,205,476,"74D8FE","5|34|6FCDF2,-14|65|70D1F5,-11|94|74D8FE,-37|-1|F1F9FB,-57|10|F4FCFE,-47|19|F4FCFE,-54|33|F4FCFE,-37|143|F4FCFE,-48|175|F4FCFE",0,0.95},
            ["货品购买按钮"] = {126,892,215,1167,"4F58DA-303030","10|-11|D1F0FF,-16|-23|D1F0FF,-17|-29|D1F0FF,-18|-43|D0EFFE,13|-42|D1F0FF,15|18|CFEDFD,9|24|D1F0FF,3|22|D1F0FF,-18|17|D1F0FF",0,0.9},
            ["跑商货品卖出按钮"] = {126,1592,221,1864,"4D56D8-303030","565|95|C8ECFE,1|89|4D56D8,19|-28|D1F0FF,-1|-43|D1F0FF,-13|28|D1F0FF,20|32|D1F0FF,17|47|D1F0FF",2,0.9},
            ["货品增加按钮"] = { 125,563,924,1165,"C6EAFF-303030","1|-13|C7EBFF,14|-1|D0F3FE,0|17|C2E7FD,-12|0|BFE3FE,18|-20|7394C2,-19|-22|5E7AAB,-20|17|5E7AAB,21|18|7597C4,-356|550|F4FCFE",2,0.9},
            ["货品卖出增加按钮"] = { 97,1244,919,1887,"C9EDFF-303030","1|-15|C8ECFE,16|-4|D2F5FE,0|9|C7EBFF,-15|-3|BFE3FE,-20|-21|5E7AAB,17|-24|7394C2,16|18|7293C1,-15|14|5F7BAB",2,0.9},
            ["谈话按钮"] = { 233,1361,356,1474,"767A8C-303030","-1|-10|D8F4FF,-1|-19|757A8C,1|-29|DAF5FF,-1|19|767A8C,0|29|D8F8FF,-31|-8|ABECFF,-38|-17|F4FCFE,-36|18|F4FCFF,-53|3|F5FDFF",0,0.9},
            ["帮派场景"] = { 1036,1732,1078,1805,"F3FBFE-303030","-5|-4|F4FCFE,-19|-3|F4FCFE,0|15|E6EFF5,-10|13|F1F9FC,-19|10|E8F1F6,0|21|F4FCFF,-20|19|F4FCFE,-19|34|F4FCFF,-8|40|EDF6FA",0,0.9},
            ["完成银票对话"] = {76,101,253,647,"F4FCFE-303030","66|-191|74D8FE,37|-201|74D8FE,65|-139|73D7FC,39|-137|74D8FE,36|-162|74D8FE,0|-76|F4FCFE,-21|-67|F4FCFE,-16|1|F4FCFE,2|88|F4FCFE",0,0.9},
            ["帮派任务折叠按钮"] = {35,223,1041,684,"182A72-303030","1|131|5075B6,-6|141|5277B8,12|-54|192A72,-11|-59|182A72,-15|-12|182A72,-14|10|182A72,-6|43|182A72,-10|67|182A72,6|-36|182A72",0,0.9},
            ["任务关闭按钮"] = { 612,1150,708,1236,"86CDFB","1|-32|3C4479,-3|30|4A4685,-31|1|4B4588,30|-1|394179,9|16|77BCF9,11|-13|73B8FA,-17|-14|A4EAFF,-17|11|91CEE9,-46|-1|7C8B51",0,0.9},
            ["地图功能按钮"] = { 516,7,864,147,"4C5B71-303030","14|-34|8BA5C1,-8|-35|8BA5C1,-12|-26|8BA5C1,-12|-16|8BA5C1,10|-4|8BA5C1,17|8|8BA5C1,-13|3|8BA5C1,-13|11|8BA5C1,-10|34|8BA5C1",0,0.95},
            ["地图大唐国境商人"] = {  579,170,741,561,"2D3238-303030","20|12|F4FCFE,46|-69|F4FCFE,48|-36|F3FBFD,47|65|F3FBFD,23|47|F4FCFE,32|60|F4FCFE,36|80|F4FCFE,48|100|F3FBFD,19|86|F4FCFE",0,0.95},
            ["地图鬼市商人"] = { 403,159,581,558,"2D3238-303030","48|-45|F4FCFE,44|-56|F4FCFE,28|-35|F4FCFE,48|57|F4FCFE,20|72|F4FCFE,20|32|F4FCFE,35|20|F4FCFE,20|-10|F4FCFE,21|-23|F4FCFE",0,0.95},
            ["继续前往按钮"] = { 351,1085,496,1398,"4D58D7-303030","10|-106|575DDE,-4|103|4D55D7,16|12|D1F0FF,-13|-42|D1F0FF,-13|26|D1F0FF,-15|44|D1F0FF,17|59|D1F0FF,15|-64|D1F0FF,11|72|CBE9FB",0,0.9},
            ["任务已完成按钮"] = {  60,734,209,1075,"D1F0FF-303030","1|-91|4E59D9,10|93|545DDE,17|-4|D2F0FF,15|-53|D2F0FF,-7|-25|D1F0FF,16|43|D2F0FF,5|46|D1F0FF,-8|50|D1F0FF,-14|-18|D1F0FF",0,0.9},
        }
    else
    end
end

local function checkBangpai()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["帮派场景"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false
        else
            return true
        end
    end)
    return rtn1,rtn2,rtn3
end

local function checkPaoshangTaskFlag()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["跑商头顶标记"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false
        else
            return true
        end
    end,5, 800)
    return rtn1,rtn2,rtn3
end

local function checkBangpaiMenuClose()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["帮派任务折叠按钮"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end,3,1000)
    return rtn1,rtn2,rtn3
end

local function checkBangpaiTaskExists()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["跑商任务已领取"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end,2,500)
    return rtn1,rtn2,rtn3
end

local function checkBangpaiTaskFinish()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["跑商任务已完成"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end,2,500)
    return rtn1,rtn2,rtn3
end

local function checkBangpaiTaskFinishGo()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["跑商任务已完成立即前往"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end,2,500)
    return rtn1,rtn2,rtn3
end

local function getTaskCloseBtnPos()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["任务关闭按钮"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end,2,500)
    return rtn1,rtn2,rtn3
end

local function GoContinu()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["继续前往按钮"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end,2,500)
    return rtn1,rtn2,rtn3
end

--任务已完成按钮
local function TaskFinish()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["任务已完成按钮"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end,2,500)
    return rtn1,rtn2,rtn3
end

local function getMapFunBtnPos()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["地图功能按钮"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end)
    return rtn1,rtn2,rtn3
end

local function getMapDTGJSR()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["地图大唐国境商人"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end)
    return rtn1,rtn2,rtn3
end

local function getMapGSSR()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["地图鬼市商人"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end)
    return rtn1,rtn2,rtn3
end


-- 判断身上是否有跑商任务已完成
local function checkPaoshangFinish()
    local panelShow = game.OpenTaskPanel()
    if panelShow then
        mlog.info("任务面板打开")
    end

    game.delay(500)
    local closed,x,y = checkBangpaiMenuClose()
    if closed then
        game.tap(x, y)
    end
    local exists,x,y= checkBangpaiTaskFinish()
    if exists then
        game.tap(x, y)
        game.delay(500)
        local goShow,x,y= checkBangpaiTaskFinishGo()
        if goShow then
            game.tap(x, y)
            return true
        end
    end

    local closeBtnExsits,x,y = game.GetCloseBtn("任务面板关闭按钮")
    if closeBtnExsits then
        mlog.info("任务面板关闭按钮")
        game.tap(x,y)
    end
    return exists
end

-- 小地图三角按钮
local function checkSnjiaoBtn()
    return true,958,1802
end

-- 世界地图按钮
local function checkWorldBtn()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["世界地图按钮"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end)
    return rtn1,rtn2,rtn3
end

-- 货品添加按钮
local function checkGoodsPlus()
--    local rtn1,rtn2,rtn3 = utils.retry(function()
--        local para = paoshangMgr.paraConfig["货品增加按钮"]
--        local itemX,itemY = game.findMultiColor(utils.unpack(para))
--        if itemX == -1 or itemY == - 1 then
--            return false,itemX,itemY
--        else
--            return true,itemX,itemY
--        end
--    end,2,500)
--    return rtn1,rtn2,rtn3

    local para = paoshangMgr.paraConfig["货品增加按钮"]
    local itemX,itemY = game.findMultiColor(utils.unpack(para))
    if itemX == -1 or itemY == - 1 then
        return false,itemX,itemY
    else
        return true,itemX,itemY
    end
end

local function checkTaskTalkBtn()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["谈话按钮"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end,10,800)
    return rtn1,rtn2,rtn3
end

local function checkGoodsSellPlus()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["货品卖出增加按钮"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end,2,500)
    return rtn1,rtn2,rtn3
end

-- 大唐国境
local function checkDTGJ()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["大唐国境"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end)

    return rtn1,rtn2,rtn3
end

-- 地图放大镜
local function getMapFDJ()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["地图放大镜"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end)

    return rtn1,rtn2,rtn3
end

-- 判断任务开关倒三角
local function checkTaskdaosanjiao()
    local para = paoshangMgr.paraConfig["任务开关倒三角"]
    local itemX,itemY = game.findMultiColor(utils.unpack(para))
    if itemX == -1 or itemY == - 1 then
        return false,itemX,itemY
    else
        return true,itemX,itemY
    end
end

-- 判断任务按钮
local function checkTaskBtn()
    local para = paoshangMgr.paraConfig["任务按钮"]
    local itemX,itemY = game.findMultiColor(utils.unpack(para))
    if itemX == -1 or itemY == - 1 then
        return false,itemX,itemY
    else
        return true,itemX,itemY
    end
end

local function checkTaskRedBtn()
    local para = paoshangMgr.paraConfig["任务按钮red"]
    local itemX,itemY = game.findMultiColor(utils.unpack(para))
    if itemX == -1 or itemY == - 1 then
        return false,itemX,itemY
    else
        return true,itemX,itemY
    end
end


local function checkTaskAndroidBtn()
    local para = paoshangMgr.paraConfig["任务按钮android"]
    local itemX,itemY = game.findMultiColor(utils.unpack(para))
    if itemX == -1 or itemY == - 1 then
        return false,itemX,itemY
    else
        return true,itemX,itemY
    end
end

-- 判断任务领取按钮
local function checkTaskAcceptBtn()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["跑商任务领取按钮"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end)
    return rtn1,rtn2,rtn3
end

local function checkTaskAcceptBtn2()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["跑商任务马上出发按钮"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end)
    return rtn1,rtn2,rtn3
end

-- 判断跑商任务前往按钮
local function checkTaskGoBtn()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["跑商任务前往"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end, 3, 500)
    return rtn1,rtn2,rtn3
end
-- 跑商任务
local function checkTaskPaoshangBtn()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["跑商任务"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end, 3, 500)
    return rtn1,rtn2,rtn3
end

-- 判断购物按钮
local function checkBugGoodsBtn()
    local para = paoshangMgr.paraConfig["跑商货品购买按钮"]
    local itemX,itemY = game.findMultiColor(utils.unpack(para))
    if itemX == -1 or itemY == - 1 then
        return false,itemX,itemY
    else
        return true,itemX,itemY
    end
end

-- 判断是否过期
local function checkTaskExpire()
    local para = paoshangMgr.paraConfig["跑商任务过期"]
    local itemX,itemY = game.findMultiColor(utils.unpack(para))
    if itemX == -1 or itemY == - 1 then
        return false,itemX,itemY
    else
        return true,itemX,itemY
    end
end

-- 货物购物按钮
local function getBugGoodsBtn()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["货品购买按钮"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end)
    return rtn1,rtn2,rtn3
end

local function checkBaihuFinishBtn()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["完成银票对话"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end)
    return rtn1,rtn2,rtn3
end

local function checkSellGoodsBtn()
    local rtn1,rtn2,rtn3 = utils.retry(function()
        local para = paoshangMgr.paraConfig["跑商货品卖出按钮"]
        local itemX,itemY = game.findMultiColor(utils.unpack(para))
        if itemX == -1 or itemY == - 1 then
            return false,itemX,itemY
        else
            return true,itemX,itemY
        end
    end)
    return rtn1,rtn2,rtn3
end

-- 跑到第一个商人
local function runShangren(index)
    -- 点击小地图
    mlog.info("跑商点击小地图")
    local sanjiaoBtn,x,y = checkSnjiaoBtn()
    if sanjiaoBtn then
        game.tap(x,y)
    end
    game.delay(2000)

    mlog.info("跑商点击世界地图")
    local worldBtnShow,x,y = checkWorldBtn()
    if worldBtnShow then
        game.tap(x,y)
    end
    game.delay(800)

    mlog.info("跑商点击大唐国境")
    local dtgjBtnShow,x,y = checkDTGJ()
    if dtgjBtnShow then
        game.tap(x,y)
    else
        return
    end

    -- 点击放大镜
    local fdjBtnShow,x,y = getMapFDJ()
    if dtgjBtnShow then
        game.tap(x,y)
    else
        return
    end

    -- 点击功能
    local funBtnShow,x,y = getMapFunBtnPos()
    if dtgjBtnShow then
        game.tap(x,y)
    else
        return
    end
    -- 点击商人
    if index == 1 then
        -- 点击大唐国境商人
        local srBtnShow,x,y = getMapDTGJSR()
        if srBtnShow then
            game.tap(x,y)
        else
            return
        end
    else
        -- 点击鬼市商人
        local srBtnShow,x,y = getMapGSSR()
        if srBtnShow then
            game.tap(x,y)
        else
            return
        end
    end

end

-- 判断身上是否有跑商任务
local function checkPaoshangFlag()
    local panelShow = game.OpenTaskPanel()
    if not panelShow then
        mlog.info("任务面板没打开")
        return false
    end
    mlog.info("任务面板打开")
    game.delay(1000)
    local closed,x,y = checkBangpaiMenuClose()
    if closed then
        game.tap(x, y)
    end
    game.delay(1000)
    local exists,x,y= checkBangpaiTaskExists()
    if exists then
        mlog.info("找到跑商任务")
        local finished = checkPaoshangFinish()
        local paoshangFinish = false
        if finished then
            paoshangMgr.curCount = paoshangMgr.curCount + 1
            mlog.info("已满去交票")
            paoshangFinish = false
            local finishTaskBtnShow,x,y = false,-1,-1
            if not finishTaskBtnShow then
                while not finishTaskBtnShow do
                    local bangpaiFlag = checkBangpai()
                    if bangpaiFlag then
                        mlog.info("已经到帮派")
                        finishTaskBtnShow,x,y = checkBaihuFinishBtn()
                        if finishTaskBtnShow then
                            game.tap(x,y)
                            mlog.info("已交票，完成跑商对话框(白虎)")
                            game.delay(1000)
                        end
                    else
                        finishTaskBtnShow,x,y = checkBaihuFinishBtn()
                        if finishTaskBtnShow then
                            game.tap(x,y)
                            mlog.info("已交票，完成跑商(白虎)")
                            return false
                        else
                            local beibaoShow = game.beibaoBtn()
                            if game.IsDisplayDead(5000) and beibaoShow then
                                game.tap(144,983)
                                game.delay(2000)
                                finishTaskBtnShow = true
                                mlog.info("已交票，完成跑商(白虎卡屏)")
                                return false
                            end
                        end
                    end
                end
            else
                game.tap(x,y)
                game.delay(500)
            end
        end
    else
        mlog.info("没找到跑商任务")
    end

    local closeBtnExsits,x,y = game.GetCloseBtn("任务面板关闭按钮")
    if closeBtnExsits then
        mlog.info("任务面板关闭按钮")
        game.tap(x,y)
    end

    return exists
end

-- 领取跑商任务
local function acceptPaoshangTask()
    local taskBtnShow,x,y = false,-1,-1

    local panelShow = game.OpenCampainPanel()
    if not panelShow then
        mlog.info("acceptPaoshangTask 任务面板没打开")
        return false
    end
    game.delay(1000)
    game.drag(916,1463,319,1460,500)
    game.delay(3000)

    local taskGoBtnShow,x,y = checkTaskGoBtn()
    if not taskGoBtnShow then
        mlog.info("没发现任务前往按钮，改换方案")
        taskGoBtnShow,x,y = checkTaskPaoshangBtn()
    end

    if taskGoBtnShow then
        mlog.info("发现任务前往按钮")
        game.tap(x,y)
        game.delay(2000)

        local taskFinishBtnShow,x,y = TaskFinish()
        if taskFinishBtnShow then
            mlog.info("发现任务已完成按钮")
            game.tap(x,y)
            game.delay(500)
            local goContinuBtnShow,x,y = GoContinu()
            if goContinuBtnShow then
                game.tap(x,y)
                game.delay(500)
            end
        end

        local findAcceptBtnShow,x1,y1 = false, -1,-1
        local waitCount = 0
        while not findAcceptBtnShow do
            mlog.info("等待接跑商任务"..tostring(waitCount))
            findAcceptBtnShow,x1,y1 = checkTaskAcceptBtn()
            if findAcceptBtnShow then
                mlog.info("发现跑商任务领取按钮1")
                game.tap(x1,y1)
            else
                local bangpaiFlag = checkBangpai()
                if bangpaiFlag then
                    mlog.info("到达帮派检查谈话按钮")
                    findAcceptBtnShow,x1,y1 = checkTaskTalkBtn()
                    if findAcceptBtnShow then
                        mlog.info("发现跑商任务领取按钮1")
                        game.tap(x1,y1)
                    end
                end
            end

            findAcceptBtnShow,x1,y1 = checkTaskAcceptBtn2()
            if findAcceptBtnShow then
                mlog.info("发现跑商任务领取按钮2")
                game.tap(x1,y1)
            end
            game.delay(2000)
            waitCount = waitCount + 1
            if waitCount > 90 then
                mlog.info("等待超时")
                return false
            end
        end
    else
        mlog.info("跑商前往按钮没找到")
    end
    game.delay(500)
    return true

end

function paoshangMgr.execTask()
    mlog.info("开始跑商 execTask")
    paoshangMgr.curCount = 1
    while paoshangMgr.curCount < paoshangMgr.maxCount do
        mlog.info("检查关闭其他无用面板")
        game.OtherPanelClose()
        local paoshangFlagBtnShow,x,y = checkPaoshangFlag()
        if paoshangFlagBtnShow then
            mlog.info("已领取跑商")
            game.delay(1000)
            local index = 1
            local paoshangFinish = false
            while true do
                game.OtherPanelClose()
                if paoshangFinish then
                    index = 3 - index
                    paoshangFinish = false
                end
                runShangren(index)
                local buyGoodsBtnShow,x,y = checkBugGoodsBtn()
                local start = LuaAuxLib.GetTickCount()
                local execTime = 0
                local taskExpire = false
                while not buyGoodsBtnShow do
                    mlog.info("检查是否已到商人处 execTime = "..tostring(execTime))
                    local taskExpire = checkTaskExpire()
                    if taskExpire then
                        mlog.info("任务过期")
                        taskExpire = true
                        break
                    end
                    buyGoodsBtnShow,x,y = checkBugGoodsBtn()
                    if not buyGoodsBtnShow then
                        local paoshangFlag = checkPaoshangTaskFlag()
                        local beibaoShow = game.beibaoBtn()
                        if not paoshangFlag and beibaoShow then
                            mlog.info("可能任务超时，需要重新接任务")
                            break
                        end
                    end
                    game.delay(1000)
                    execTime = (LuaAuxLib.GetTickCount() - start) / 1000
                    if execTime > 60*3 then
                        mlog.info("检查超时execTime ="..tostring(execTime))
                        break
                    end
                end

                if taskExpire then
                    break
                end
                mlog.info("已到商人处")
                if buyGoodsBtnShow then
                    game.tap(x,y)
                    -- 检查是否有东西需要卖出
                    game.delay(1000)
                    local goodsSellPlusBtnShow,x,y = checkGoodsSellPlus()
                    if goodsSellPlusBtnShow then
                        mlog.info("出售货品")
                        while goodsSellPlusBtnShow do
                            while goodsSellPlusBtnShow do
                                game.tap(x,y)
                                game.delay(300)
                                goodsSellPlusBtnShow,x,y = checkGoodsSellPlus()
                            end
                            -- 点击卖出
                            local goodsBuyBtn,x,y = checkSellGoodsBtn()
                            if goodsBuyBtn then
                                game.tap(x,y)
                            end
                            game.delay(1000)
                            goodsSellPlusBtnShow,x,y = checkGoodsSellPlus()
                            if not goodsSellPlusBtnShow then
                                break
                            end
                        end

                        local finished = checkPaoshangFinish()
                        if finished then
                            paoshangMgr.curCount = paoshangMgr.curCount + 1
                            mlog.info("已满去交票")
                            paoshangFinish = false
                            index = 1
                            local finishTaskBtnShow,x,y = false,-1,-1
                            if not finishTaskBtnShow then
                                while not finishTaskBtnShow do
                                    local bangpaiFlag = checkBangpai()
                                    if bangpaiFlag then
                                        mlog.info("已经到帮派")
                                        finishTaskBtnShow,x,y = checkBaihuFinishBtn()
                                        if finishTaskBtnShow then
                                            game.tap(x,y)
                                            mlog.info("已交票，完成跑商对话框(白虎)")
                                            game.delay(1000)
                                        end
                                    else
                                        finishTaskBtnShow,x,y = checkBaihuFinishBtn()
                                        if finishTaskBtnShow then
                                            game.tap(x,y)
                                            mlog.info("已交票，完成跑商(白虎)")
                                        else
                                            local beibaoShow = game.beibaoBtn()
                                            if game.IsDisplayDead(5000) and beibaoShow then
                                                game.tap(144,983)
                                                game.delay(2000)
                                                finishTaskBtnShow = true
                                                mlog.info("已交票，完成跑商(白虎卡屏)")
                                            end
                                        end
                                    end
                                end
                            else
                                game.tap(x,y)
                                game.delay(500)
                            end
                            game.delay(1000)
                            break
                        else
                            game.delay(1000)
                        end
                    end
                    mlog.info("准备买入")
                    local goodsPlusBtnShow,x,y = checkGoodsPlus()
                    local count = 1
                    while goodsPlusBtnShow do
                        mlog.info("购买货品")
                        game.tap(x,y)
                        game.delay(300)
                        mlog.info("购买货品>>>>>")
                        count = count + 1
                        if count > 20 then
                            local goodsBuyBtnShow,x,y = getBugGoodsBtn()
                            if goodsBuyBtnShow then
                                game.tap(x,y)
                                game.delay(1000)
                            end
                        end
                        goodsPlusBtnShow,x,y = checkGoodsPlus()
                        mlog.info("goodsPlusBtnShow>>>>>"..tostring(goodsPlusBtnShow))
                    end
                    local goodsBuyBtnShow,x,y = getBugGoodsBtn()
                    if goodsBuyBtnShow then
                        game.tap(x,y)
                    end
                    -- 关闭
                    game.CloseBtnByKey("跑商货品界面关闭按钮")
                    mlog.info("已买够，去往第二个商人")
                    game.delay(2000)
                    paoshangFinish = true
                else
                    break
                end
            end

            mlog.info("已完跑商数量：", paoshangMgr.curCount)
        else
            mlog.info("未领取跑商")
            local succ = acceptPaoshangTask()
            while not succ do
                mlog.info("检查关闭其他无用面板")
                game.OtherPanelClose()
                game.delay(1000)
                mlog.info("重新尝试接受任务")
                succ = acceptPaoshangTask()
            end
        end
    end

end